package com.shenmazong.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.order.pojo.TbCity;
import com.shenmazong.order.service.TbCityService;
import com.shenmazong.order.mapper.TbCityMapper;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.IdVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class TbCityServiceImpl extends ServiceImpl<TbCityMapper, TbCity>
    implements TbCityService{

    @Autowired
    TbCityMapper tbCityMapper;

    @Override
    public ResultResponse listCities(IdVo idVo) {
        //--1 构造条件
        QueryWrapper<TbCity> wrapper = new QueryWrapper<>();
        if(idVo.getId().equals(-1)) {
            wrapper.lambda().orderByAsc(TbCity::getCid);
        }
        else {
            wrapper.lambda().eq(TbCity::getPid, idVo.getId()).orderByAsc(TbCity::getCid);
        }

        //--2 查询
        List<TbCity> tbCities = tbCityMapper.selectList(wrapper);

        //--3 返回列表
        return ResultResponse.SUCCESS(tbCities);
    }
}




